﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

using SharedGenomics.Core;

namespace SharedGenomics.Domain
{
    [DataContract]
    public class IdFileSchemaColumn : FileSchemaColumn
    {
        public IdFileSchemaColumn()
            : base(ColumnDistribution.Id)
        {
        }

        private const string INVALID_VALUE_ERROR = "Cannot have emtpy identifier";

        public override void Validate(string value, ValidationMessageCollection validationMessages)
        {
            if (value.IsEmptyOrWhitespace())
            {
                validationMessages.AddErrorMessage(INVALID_VALUE_ERROR);
            }
        }

        public override object Parse(string value)
        {
            if (value.IsEmptyOrWhitespace())
                throw new ArgumentException(INVALID_VALUE_ERROR);

            return value;
        }

        [OnDeserializing]
        internal void OnDeserialising(StreamingContext context)
        {
            this.Initialize();
        }

        public override bool IsValidPhenotypeColumn
        {
            get { return false; }
        }
    }
}
